package com.wondream.myframework.web;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.annotation.Reference;
import com.wondream.myframework.base.utils.JacksonUtil;
import com.wondream.myframework.base.utils.ResponseUtil;
import com.wondream.myframework.trade.service.CommonService;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;
import java.util.Map;

@RestController
@RequestMapping("/profit-sharing")
public class CommonController {

    @Reference(version = "1.0.0")
    private CommonService commonService;

    @GetMapping("/hello")
    public String hello(){
        return "hello world!";
    }

    @GetMapping("/testDubbo")
    public String testDubbo(){
        return commonService.testDubbo();
    }

    @RequestMapping("/bbgPay")
    public Object bbgPay(@RequestParam Map<String, String> params)
    {
        String type = params.get("type");
        Class clazz = commonService.getClass();
        Map<String, Object> dataMap = null;
        try {
            Method method = clazz.getMethod(type, String.class);
            dataMap = (Map<String, Object>)method.invoke(commonService, JSONUtils.toJSONString(params));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseUtil.ok(dataMap);
    }

}
